package net.pugsplace.gpremacy.state;

import net.pugsplace.gpremacy.rules.Unit;
import net.pugsplace.gpremacy.rules.UnitType;

/**
 * This represents a particular unit of type UnitType. There is one of these for
 * each unit in play, while only one UnitType per type in existence.
 */
public class AbstractUnit implements Unit {
	private static final long serialVersionUID = 7361115981720189744L;
	private String name;
	private final int countryId;
	private final UnitType unitType;

	/** Create a new unit of type Type owned by countryId id */
	public AbstractUnit(UnitType type, int id) {
		unitType = type;
		countryId = id;
		name = unitType.getType();
	}

	/** Returns the customizable name of the unit */
	public String getName() {
		return name;
	}

	/** The owner ID of this unit */
	public int getOwnerCountryId() {
		return countryId;
	}

	/** Returns the "type" of unit, such as "Soldier" */
	public UnitType getType() {
		return unitType;
	}

	/** Change the unit's customizable name */
	public void setName(String newName) {
		name = newName;
	}

	@Override
	public String toString() {
		return name + " (" + unitType.getType() + ")";
	}
}
